<?php
class ClassifyModel extends Model{
	protected $_validate =array(
		array('name','require','分类名不能为空',1),
		array('img','require','分类图片不能为空',1),
		array('img','url','分类图片地址不正确',1),
	);
	
	protected $_auto = array (
		array('token','gettoken',self::MODEL_INSERT,'callback'),
	);
	
	public function gettoken(){
		return session('token');
	}
	
	/**
	 * 得到树型下拉列表<option>内容
	 * @param string $token，表示获得这个token下的所有子级
	 * @param int $eid 要排除的数据id，一般为自身id
	 * @param string $sid 要加入的选中value值,如9或者9,T1那么对应value=‘9’ 或者value=‘9,T1’的option将被标记selected
	 * @param string $str 要生成的字串，默认为<option value='\$id'>\$spacer\$name</option>
	 * @return string
	 */
	public function get_selectoption_str($token, $eid, $sid, $str){
		$Tree = new Tree();
		$Tree->icon = array('&nbsp;&nbsp;│ ','&nbsp;&nbsp;├─ ','&nbsp;&nbsp;└─ ');
		$Tree->nbsp = '&nbsp;&nbsp;';
		$where['token']=$token;
	
		if($eid){
			$where['id']= array('neq',$eid);
			$where['pid']= array('neq',$eid);
		}
	
		$info=$this->where($where)->field('id,pid,name')-> select();
	
		if(!$str){
			$str  = "<option value='\$id'>\$spacer\$name</option>";
		}
	
		$Tree->init($info);
		$html_tree = $Tree->get_tree(-1, $str);
	
		if($sid){
			$html_tree = str_ireplace('value=\''.$sid.'\'', 'value=\''.$sid.'\' selected="selected"', $html_tree);
		}
	
		return $html_tree;
	}
}